package com.freejava.test_websocket.chatobject;

import com.alibaba.fastjson.JSON;

/**
 * WebSocket 聊天消息类
 */
public class Message {

    // 进入聊天
    public static final String ENTER = "ENTER";
    // 聊天
    public static final String TALK = "TALK";
    // 退出聊天
    public static final String QUIT = "QUIT";

    // 消息类型
    private String type;

    // 发送人
    private String username;

    // 发送消息
    private String message;

    // 在线人数
    private int onlineCount;

    // 返回处理后的json结果
    public static String toJsonResult(String type, String username, String msg, int onlineCount) {
        return JSON.toJSONString(new Message(type, username, msg, onlineCount));
    }

    public Message(String type, String username, String msg, int onlineCount) {
        this.type = type;
        this.username = username;
        this.message = msg;
        this.onlineCount = onlineCount;
    }

    //此处省略get/set方法

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getOnlineCount() {
        return onlineCount;
    }

    public void setOnlineCount(int onlineCount) {
        this.onlineCount = onlineCount;
    }

    public static String getENTER() {
        return ENTER;
    }

    public static String getTALK() {
        return TALK;
    }

    public static String getQUIT() {
        return QUIT;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}
